<?php
if (isset($_COOKIE["ImOnline"])){
	//print($_COOKIE["ImOnline"]);
	//print("Welcome back " . $_COOKIE["Username"]);
} else {
	die("<br>You have no access to this page. <br><a href=\"index.php\">Please go to main page</a>");
	//print($_COOKIE["imonline"]);
	};
include("../config.php");
$sid=$_POST["sid"];
$uname=$_POST["uname"];
$days=$_POST["days"];
$hours=$_POST["hours"];
$status = intval($_POST["usertype"]);
$Ustatus = $_COOKIE["Status"];
if(intval($days) == 0 and intval($hours) == 0 and $Ustatus == "Owner"){
	$time = 0;
}else{
	if (intval($days) <= 0){
		$days = 1;
	};
	if (intval($hours) <= 0){
		$hours = 24;
	};
	$bantime = intval($days)*intval($hours)*60*60;
	$time = time()+$bantime;
};
$banner = $_COOKIE["Username"];
$con = mysql_connect($host, $username, $password);
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  };
if($status < $_COOKIE["StatusNum"]){
	mysql_select_db($db, $con);
	$sql="SELECT * FROM bans WHERE SteamID='$sid'";
	$result = mysql_query($sql) or die("ERROR: couldt execute query!");
	$count=mysql_num_rows($result);
	if($count == 1) {
		header("Location: ../users.php?error=User is already banned!");
		die("");
	}else{
		$sql="INSERT INTO Bans (`SteamID`,`Nick`,`Banner`,`Comment`,`Bantime`)VALUES ('$sid','$uname','$banner','User was banned via website!',$time)";
		$result = mysql_query($sql) or die("Error: Couldt ban user");
	if ($bantime >= 86400) {
		$sql="UPDATE users SET Banmarks= Banmarks+1 WHERE SteamID='$sid'";
		$result = mysql_query($sql) or die("Error: Couldnt Add banmark");
	};
	header("Location: ../users.php?error=Banned user!");
	die("");
	};
	}else{
		header("Location: ../users.php?error=The user you were trying to ban has higher or equal status!");
		die("");
	};
mysql_close($con);
?>